﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string sql = "select * from BanQuanTri ";
        DataTable bqt = Database.GetData(sql);
        lbxBanQuanTri.DataSource = bqt;
        lbxBanQuanTri.DataBind();
    }
    public int getCount(DataTable dem)
    {
        int d = 0;
        foreach (DataRow row in dem.Rows)
        {
            d = int.Parse(row["DEM"].ToString());
        }
        return d;
    }
    public void TraLoiThacMacTM(object sender, EventArgs e)
    {
        string sql = "SELECT count(*) as DEM from thacmac";
        DataTable dem = Database.GetData(sql);
        int d = this.getCount(dem);
        string username = Session["user"].ToString();
        string bqt = lbxBanQuanTri.Text;
        string tieude = txtTieuDeTM.Text;
        string noidung = txtNoiDungTM.Text;
        string email = txtEmail.Text;
        string sqlIn = "INSERT INTO ThacMac values(@mathacmac,@banquantri,@username,@tieude,@noidung,@email)";

        Database.ExecuteNonQuery(sqlIn, "@mathacmac", "TM" + (d + 1), "@banquantri", bqt, "@tieude", tieude, "@noidung", noidung, "@email", email);
    }
}